/**
 * 
 */
package com.jie.eclipse.pan.swtitem.actiongroup;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.viewers.CheckboxTableViewer;

import com.jie.eclipse.pan.config.BaseConfig;
import com.jie.eclipse.pan.data.BaseDataEntities;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.swtitem.table.PTableViewer;
import com.jie.eclipse.pan.swtitem.widgets.BaseComposite;
import com.jie.eclipse.pan.utils.Utils;
import com.jie.eclipse.pan.utils.handle.FileHandle;

/**
 * @author yanjie
 *
 */
public class TableActionGroup extends BaseActionGroup{
	/**
	 * @param bc
	 * @param fileHandle
	 */
	public TableActionGroup(BaseComposite bc, FileHandle fileHandle) {
		super(bc, fileHandle);
	}

	private class SaveRowAction extends Action{
		public SaveRowAction() {
			this.setImageDescriptor(getImageDesc("icon_rowsave.gif"));
			this.setText("保存");
		}
		
		@Override
		public void run() {
			PTableViewer  tv2 = (PTableViewer)getBaseComposite().getDataInstance().gpov("tv2");//已选栏位表格选择器
			if(tv2 != null){
				BaseDataEntities rows = new BaseDataEntities();
				for (int i = 0; i < tv2.getTable().getItemCount(); i++) {
					BaseDataEntity row = (BaseDataEntity)tv2.getElementAt(i);
					BaseDataEntity temp = new BaseDataEntity();
					row.CopyTo(temp, false);
					temp.spsv(BaseConfig.TAG_LABLE,temp.gpsv("caption"));
					rows.add(temp);
				} 
				getFileHandle().modelToXml(rows);
			}
			getFileHandle().getPllFormEditor().doSave(null);
		}
	}
	
	public void fillActionToolbars (ToolBarManager actionBarManager){
		SaveRowAction saverowAction = new SaveRowAction();
		actionBarManager.add(createActionContributionItem(saverowAction));
		actionBarManager.update(true);
	}
}
